﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Compiler.Extension.Values;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using Roslyn.Services;

namespace Roslyn.Compiler.Extension.Attributes.Converter
{
    public abstract class AttributeConverter
    {
        #region fields/properties
        private AttributeSyntax _syntax;
        private ISemanticModel _semanticModel;
        private ISolution _solution;

        protected AttributeSyntax AttributeSyntax
        {
            get { return _syntax; }
            set { _syntax = value; }
        }
       
        protected ISemanticModel SemanticModel
        {
            get { return _semanticModel; }
            set { _semanticModel = value; }
        }
        
        protected ISolution Solution
        {
            get { return _solution; }
            set { _solution = value; }
        }
        #endregion

        public static AttributeConverter GetInstance(ISolution solution, ISemanticModel semanticModel, AttributeSyntax syntax)
        {
            
            AttributeConverter attributeConverter = null;
            CommonTypeInfo typeInfo = semanticModel.GetTypeInfo(syntax);
            string attributeName = typeInfo.Type.Name;
            switch (attributeName)
            {
                case Constants.AttributeName.Any:
                    attributeConverter = new AnyAttributeConverter();
                    break;
                case Constants.AttributeName.Option:
                    attributeConverter = new OptionAttributeConverter();
                    break;
                case Constants.AttributeName.Bare:
                    attributeConverter = new BareAttributeConverter();
                    break;
                default:
                    attributeConverter = new BareAttributeConverter();
                    break;
            }

            attributeConverter.AttributeSyntax = syntax;
            attributeConverter.SemanticModel = semanticModel;
            attributeConverter.Solution = solution;
            return attributeConverter;
        }

        #region Convert Methods
        public abstract FieldDeclarationSyntax ConvertField(FieldDeclarationSyntax fieldSyntax);

        public abstract PropertyDeclarationSyntax ConvertProperty(PropertyDeclarationSyntax propertySyntax);

        public abstract MethodDeclarationSyntax ConvertMethod(MethodDeclarationSyntax methodSyntax);
        #endregion

        public abstract string Validate(FieldDeclarationSyntax declarationSyntax);

        
    }
}
